<?php
/**
 * Created by PhpStorm.
 * User: QK
 * Date: 2018-07-25
 * Time: 下午 4:31
 */
namespace app\blog\controller;
use app\blog\model\CouModel as cou;
use cmf\controller\AdminBaseController;

class CouController extends AdminBaseController{
    /**
     * 类别列表页面
    */
    public function _initialize()
    {
        parent::_initialize();
        $this->cou=new cou();
    }
    public function index()
    {
        $param = $this->request->param();
        $rest       = $this->cou->index($param);
        $this->assign('data',$rest);
        $this->assign('page',$rest->render());
        return $this->fetch('cou/index');
    }
    /*添加优惠券*/
    public function add()
    {
        $param = $this->request->param();
        $rest       = $this->cou->index($param);
        $this->assign('data',$rest);
        $this->assign('page',$rest->render());
        return $this->fetch('cou/add');
    }
    /*接收数据*/
    public function addpost()
    {
        $param = $this->request->param();
        $rest       = $this->cou->add($param);
        $this->success($rest);
    }
    /**
     * 优惠券修改页面
    */
    public function detail(){
        //根据id获取该条类别信息
        $array          = $this->request->param();
        $where['id']=$array['id'];
        $rest        = $this->cou->getcone($where);
        $this->assign('data',$rest);
        return $this->fetch('cou/detail');
    }
    /*
     * 优惠券修改操作
     */
    public function detailpost(){
        $date        = $this->request->param();
        $where['id']=$date['id'];
        $data['cause']=$date['cause'];
        $data['s_time']=strtotime($date['s_time']);
        $data['e_time']=strtotime($date['e_time']);
        $data['money']=$date['money'];
        $rest        = $this->cou->detail($where,$data);
        $this->success($rest);
    }
    /*
     * 优惠券删除操作
     */
    public function del(){
        $date        = $this->request->param();
        $rest        = $this->cou->del($date);
        if($rest['num'] != 0){
            $this->success($rest['con'],url("cou/index"));
        }else{
            $this->error($rest['con'],url("cou/index"));
        }
    }
    /*禁用启用功能*/
    public function upstatus(){
        $date        = $this->request->param();
        $where       = array();
        $where['id'] = $date['id'];
        $date['status']=$date['status'];
        $rest        = $this->cou->detail($where,$date);
        if($rest != false){
            $this->success("操作成功！",url("cou/index"));
        }else{
            $this->error('操作失败',url("cou/index"));
        }
    }
}